package com.traveling.hztraveling.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.traveling.hztraveling.entity.po.HzCulture;
import com.traveling.hztraveling.entity.po.HzRoutes;
import com.traveling.hztraveling.entity.vo.Result;
import com.traveling.hztraveling.service.IHzCultureService;
import com.traveling.hztraveling.service.IHzRoutesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class OrdersController {

    private final IHzCultureService hzCultureService;

    private final IHzRoutesService hzRoutesService;


    @GetMapping("/orders/activity")
     public Result<Page<HzCulture>> getOrders(@Param( "current") Integer current, @Param( "size") Integer size, @Param( "status") String status ,  @Param( "type") String type) {
        log.info( "获取activity订单信息:{},{},{},{}",current,size, status,type );
            Page<HzCulture> list = hzCultureService.getOrders(current,size, status);
            log.info( "获取activity订单信息:{}",Result.success(list));
            return Result.success(list);
    }

    @GetMapping("/orders/route")
    public Result<Page<HzRoutes>> getOrders(@Param( "current") Integer current, @Param( "size") Integer size) {
        log.info( "获取route订单信息:{},{},{},{}",current,size);
        Page<HzRoutes> list = hzRoutesService.getOrders(current,size);
        return Result.success(list);
    }


    @GetMapping("/orders/search")
    public Result<Page<HzCulture>> searchOrders(@Param( "current") Integer current, @Param( "size") Integer size ,@Param("keyword") String keyword) {
        log.info( "获取订单信息:{}",keyword);
        Page<HzCulture> list = hzCultureService.getOrders( current,size, null, keyword);
        return Result.success(list);
    }

    @GetMapping("/orders/route/search")
    public Result<Page<HzRoutes>> searchRouteOrders(@Param( "current") Integer current, @Param( "size") Integer size,@Param("keyword") String keyword) {
        log.info( "获取订单信息:{}",keyword);
        Page<HzRoutes> list = hzRoutesService.getRouteOrders( current,size, null, keyword);
        return Result.success(list);
    }

    @PutMapping("/orders/{orderId}/refund")
    public Result getRefund(@PathVariable("orderId") Integer orderId) {
        log.info( "获取订单信息:{}",orderId);
        HzCulture hzCulture = hzCultureService.getRefund(orderId);
        return Result.success(hzCulture);
    }

}
